package com.leet.tree;

public class LowestCommonAncestor {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if((root.val-p.val < 0 && root.val-q.val > 0)||(root.val-p.val > 0 && root.val-q.val < 0)){
            return root;
        }
        lowestCommonAncestor(root.left,p,q);
        lowestCommonAncestor(root.right,p,q);
        return root;
    }
}
